<template>
  <div class="workTicketChange flowCloumn h100">
    <div class="constentmain h100">
      <list-table-new
        v-bind="tableSetting"
        ref="klTable"
        @selectChange="selectChange"
        @selectAll="selectAll"
        @defaultSelection="checkedUser"
      ></list-table-new>
    </div>
  </div>
</template>
<script>
import { queryPatrolPointList } from "@/api/productionPlan/patrolPlan.js";
export default {
  props: {
    pointList: {
      type: Array,
      default: () => {
        return [];
      },
    },
  },
  data() {
    return {
      tableSetting: {
        selectionShow: true,
        showFilterBtn: false,
        showCustomBtn: false,
        searchObj: {
          searchMethod: (params, sortStr) => {
            this.getTableData(params, sortStr);
          },
          queryData: {
            page: 1,
            pageSize: 15,
          },
          searchArr: [
            {
              type: "input",
              label: "巡视点名称",
              model: "name",
            },
            {
              type: "organization",
              label: "所属单位",
              model: "pointDeptName",
              idsStr: "pointDeptId",
            },
          ],
        },
        //过滤器的值
        filterFormData: {},
        //过滤器的默认值
        defaultFilterData: {},
        userCustomData: [],
        actionList: [],
        column: [
          {
            label: "巡视点名称",
            prop: "name",
          },
          {
            label: "所属单位",
            prop: "pointDeptName",
          },
        ],
        paginationObj: {
          pageSizes: [15, 30, 50, 100],
        },
        totalNumber: 0,
        //表格方法
        tableMethods: {
          //点击行的方法
          rowClick: (row) => {
            //this.goDetailPage(row, "patrolPointDetails", "edit");
          },
        },
      },
      checkData: [],
    };
  },
  mounted() {
    this.checkData = JSON.parse(JSON.stringify(this.pointList));
    this.updateData();
  },
  methods: {
    updateData() {
      this.$refs.klTable.searchData();
    },
    // 获取表格数据
    getTableData(params, sortStr) {
      let queryData = Object.assign({}, params);
      if (sortStr.length > 0) {
        queryData.orders = sortStr;
      }
      queryPatrolPointList(queryData).then((res) => {
        this.$set(this.tableSetting, "tableData", res.data.list);
        this.$set(this.tableSetting, "totalNumber", res.data.total);
        this.checkedUser();
      });
    },
    //勾选已选巡视点
    checkedUser() {
      this.checkData.forEach((item) => {
        this.tableSetting.tableData.forEach((value) => {
          if (value.id == item.pointId) {
            this.$refs.klTable.selectioned(value);
          }
        });
      });
    },
    selectAll(selected) {
      this.tableSetting.tableData.forEach((item) => {
        this.selectChange(selected, item);
      });
    },
    //添加或取消已选用户
    selectChange(selected, row) {
      if (selected) {
        let point = {
          pointId: row.id,
          name: row.name,
        };
        this.checkData.push(point);
      } else {
        this.checkData.forEach((item, i) => {
          if (item.pointId === row.id) {
            this.checkData.splice(i, 1);
            return;
          }
        });
      }
    },
    getSelectData() {
      return this.checkData;
    },
  },
};
</script>
<style lang="less" scoped>
.workTicketChange {
  .constentmain {
    margin-left: 10px;
  }
}
.flowCloumn {
  display: flex;
  flex-flow: column nowrap;
}
</style>